package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.FindLunboDetailsModle;


/**
 * Created by lanouhn on 16/9/2.
 */
public class FindLunBoDetailsAdapter extends RecyclerView.Adapter<FindLunBoDetailsAdapter.MyViewholder>{
    private Context mContext;
    private FindLunboDetailsModle detailsModles;
    private int cont;

    public FindLunBoDetailsAdapter(Context mContext, FindLunboDetailsModle detailsModles) {
        this.mContext = mContext;
        this.detailsModles = detailsModles;
        this.cont = detailsModles.getArticle_sections().size()+1;
    }

    @Override
    public MyViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_find_lunbo_details,null);
        MyViewholder myViewholder=new MyViewholder(view);
        return myViewholder;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }


    @Override
    public void onBindViewHolder(MyViewholder holder, int position) {

        if (position==0){
            Picasso.with(mContext).load(detailsModles.getImage_url()).into(holder.iv);
            holder.iv.setVisibility(View.VISIBLE);
            holder.tv_zjz_zhuti.setText(detailsModles.getName());
            holder.tv_zjz_neirong.setText(detailsModles.getTitle());
            holder.llt.setVisibility(View.VISIBLE);
        }else {
            int i=position-1;
            holder.llt.setVisibility(View.GONE);
            holder.iv.setVisibility(View.GONE);
            if (!"".equals(detailsModles.getArticle_sections().get(i).getDescription())){
                if (!"".equals(detailsModles.getArticle_sections().get(i).getTitle())){
                    holder.tv_zhuti.setText(detailsModles.getArticle_sections().get(i).getTitle());
                    holder.tv_neirong.setText(detailsModles.getArticle_sections().get(i).getDescription());
                    holder.tv_zhuti.setVisibility(View.VISIBLE);
                    holder.tv_neirong.setVisibility(View.VISIBLE);
                }else {
                    holder.tv_ziji_neirong.setText(detailsModles.getArticle_sections().get(i).getDescription());
                    holder.tv_ziji_neirong.setVisibility(View.VISIBLE);
                }
            }
            if (!"".equals(detailsModles.getArticle_sections().get(i).getImage_url())){
                Picasso.with(mContext).load(detailsModles.getArticle_sections().get(i).getImage_url()).into(holder.iv_da);
                holder.iv_da.setVisibility(View.VISIBLE);
            }
        }

    }

    @Override
    public int getItemCount() {
        return cont;
    }


    public class MyViewholder extends RecyclerView.ViewHolder{

        private ImageView iv,iv_da;
        private LinearLayout llt;
        private TextView tv_zjz_zhuti,tv_zjz_neirong,tv_zhuti,tv_neirong,tv_ziji_neirong;

        public MyViewholder(View itemView) {
            super(itemView);
            iv= (ImageView) itemView.findViewById(R.id.find_lunbo_details_item_iv);
            llt= (LinearLayout) itemView.findViewById(R.id.find_lunbo_details_item_zhongjianzi);
            tv_zjz_zhuti= (TextView) itemView.findViewById(R.id.find_lunbo_details_item_zjz_zhuti);
            tv_zjz_neirong= (TextView) itemView.findViewById(R.id.find_lunbo_details_item_zjz_neirong);
            tv_zhuti= (TextView) itemView.findViewById(R.id.find_lunbo_details_item_zhuti);
            tv_neirong= (TextView) itemView.findViewById(R.id.find_lunbo_details_item_neirong);
            tv_ziji_neirong= (TextView) itemView.findViewById(R.id.find_lunbo_details_item_ziji);
            iv_da= (ImageView) itemView.findViewById(R.id.find_lunbo_details_item_iv_da);

        }
    }

}
